package com.module02.demo01;

public class ArrayDemo {

    public static void main(String[] args) {

        //定义一个长度为[16][16]的整型二维数组
        int[][] arr = new int[16][16];

        //给数组赋值
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                if (i + j == 15 || i == j) {
                    arr[i][j] = 0;
                } else {
                    arr[i][j] = 1;
                }
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
        //计算左上角到右下角和右上角到左下角所有元素的累加并打印
        //使用变量来接收结果

        System.out.println("================================");
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                if (i + j == 15 || i == j) {
                    sum += arr[i][j];
                }
            }
        }

        //打印结果
        System.out.println(sum);


    }
}
